﻿using B.S.DataBase.MyProject.Domain.productionworkorder;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.SCWorkOrderCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.SCWorkOrderCommandHandler
{
    /// <summary>
    /// 查询生产工单的物品名称命令处理方法
    /// </summary>
    public class SCWuPinQueryCommandHandler:IRequestHandler<SCWuPinQueryCommand,APIResult<List<item_classification_detail>>>
    {
        /// <summary>
        /// 生产单号的物品表的仓储接口
        /// </summary>
        private readonly IBaseRepository<item_classification_detail> iRepo;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="iRepo"></param>
        public SCWuPinQueryCommandHandler(IBaseRepository<item_classification_detail>iRepo)
        {
            this.iRepo = iRepo;
        }
        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<item_classification_detail>>> Handle(SCWuPinQueryCommand request, CancellationToken cancellationToken)
        {
             
            try
            {
                APIResult<List<item_classification_detail>> result = new APIResult<List<item_classification_detail>>();
                var list = await iRepo.GetAll();
                result.data = list.ToList();
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.Count = list.Count();
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }


        }



    }
}
